package com.jf.yytgd.converter;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * Created with IntelliJ IDEA
 * Description: 分页转换器
 * User:22954
 * Date:2025-02-07
 * Time:1:09
 */
@Mapper
public interface PageConverter {
    PageConverter INSTANCE = Mappers.getMapper(PageConverter.class);

    default <T, U> Page<U> convert(Page<T> source, List<U> records) {
        Page<U> target = new Page<>();
        target.setCurrent(source.getCurrent());
        target.setSize(source.getSize());
        target.setTotal(source.getTotal());
        target.setOptimizeCountSql(source.optimizeCountSql());
        target.setCountId(source.countId());
        target.setMaxLimit(source.maxLimit());
        target.setOrders(source.orders());
        target.setSearchCount(source.searchCount());
        target.setOptimizeJoinOfCountSql(source.optimizeJoinOfCountSql());

        target.setRecords(records);
        return target;
    }
}
